/*
 * Line.fx
 *
 * Created on 04.10.2009, 22:11:53
 */

package javafx179labs.nez.hr.gui;

/**
 * @author civil
 */

import javafx.scene.Group;
import javafx.scene.control.Button;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingComboBox;
import javafx.ext.swing.SwingComboBoxItem;

def bheight:Float = 21;
def lbwidth:Float = 28;
def rbwidth:Float = 40;
public function makeLine (text:String, setter:function(:String):Void) {
    var txt = text;
    var mode: Group;
    var edit: Group;


    var efield = SwingTextField {
        columns: 27
        text: txt
    }

    var main = Group {
        content: [
                //text zone
                SwingTextField {
                    editable: false
                    columns: 27
                    text: bind txt
                },

                Button {
                    text: "edit"
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: function () {
                        efield.text = txt;
                        mode = edit
                    }
                }
        ]
    }

    edit = Group {
        content: [
                efield,

                Button {
                    text: "ok"
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: function () {
                        txt = efield.text;
                        setter(txt);
                        mode = main
                    }
                },

                Button {
                    text: "cancel"
                    height: bheight
                    width: rbwidth
                    layoutX: 338
                    action: function () {
                        mode = main
                    }
                }
        ]
    }

    mode = main;

    Group {
        content: bind [mode]
    }

}

public function optLine (text:String, setter:function(:String):Void, optText: String, opt:function():Void) {
    var txt = text;
    var mode: Group;
    var edit: Group;


    var efield = SwingTextField {
        columns: 27
        text: txt
    }

    var main = Group {
        content: [
                //text zone
                SwingTextField {
                    editable: false
                    columns: 27
                    text: bind txt
                },

                Button {
                    text: "edit"
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: function () {
                        efield.text = txt;
                        mode = edit
                    }
                }

                Button {
                    text: optText
                    height: bheight
                    width: rbwidth
                    layoutX: 338
                    action: opt
                }
        ]
    }

    edit = Group {
        content: [
                efield,

                Button {
                    text: "ok"
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: function () {
                        txt = efield.text;
                        setter(txt);
                        mode = main
                    }
                },

                Button {
                    text: "cancel"
                    height: bheight
                    width: rbwidth
                    layoutX: 338
                    action: function () {
                        mode = main
                    }
                }
        ]
    }

    mode = main;

    Group {
        content: bind [mode]
    }

}

public function makeLine (text:String, makeItems: function():SwingComboBoxItem[],
                            setter:function(:Object):Void) {

    var txt = text;
    var mode: Group;
    var edit: Group;


    var eBox = SwingComboBox {
        width: 302
        height: bheight
        items: bind makeItems()
    }


    var main = Group {
        content: [
                //text zone
                SwingTextField {
                    editable: false
                    columns: 27
                    text: bind txt
                },

                Button {
                    text: "edit"
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: function () {
                        mode = edit
                    }
                }
        ]
    }

    edit = Group {
        content: [
                eBox,

                Button {
                    text: "ok"
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: function () {
                        txt = eBox.selectedItem.text;
                        setter(eBox.selectedItem.value);
                        mode = main
                    }
                },

                Button {
                    text: "cancel"
                    height: bheight
                    width: rbwidth
                    layoutX: 338
                    action: function () {
                        mode = main
                    }
                }
        ]
    }

    mode = main;

    Group {
        content: bind [mode]
    }

}

public function makeAddLine (adder:function(:String):Void) {
    var txt: String;
    var edit: Group;


    var efield = SwingTextField {
        columns: 27
        text: txt
    }

    edit = Group {
        content: [
                efield,

                Button {
                    text: "ok"
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: function () {
                        txt = efield.text;
                        adder(txt);
                    }
                },
        ]
    }


    Group {
        content: bind [edit]
    }

}

public function staticLine (text:String, optText: String, opt:function():Void) {

    var main = Group {
        content: [
                //text zone
                SwingTextField {
                    editable: false
                    columns: 27
                    text: text
                },

                Button {
                    text: optText
                    height: bheight
                    width: lbwidth
                    layoutX: 305
                    action: opt
                }
        ]
    }

    Group {
        content: main
    }

}